package any.incubator;

import java.math.BigDecimal;
import java.util.Iterator;
import java.util.Map.Entry;

import any.Any;
import any.SequentialAny;
import any.impl.util.MapEntry;
import any.impl.util.Utils;

public class NumberGenerator extends BaseSequentialAny {

	@SuppressWarnings("synthetic-access")
	class EntriesIterator implements Iterator<Entry<String, ? extends SequentialAny>> {
		private BigDecimal next = start;
		public boolean hasNext() {
			return stop == null || next.compareTo(stop) < 0;
		}
		public void remove() throws UnsupportedOperationException {
			throw new UnsupportedOperationException();
		}
		public Entry<String, ? extends SequentialAny> next() {
			MapEntry<String, Any> entry = MapEntry.createAnyEntry(next);
            next = next.add(step);
            
			return entry;
        }
	}

	private final BigDecimal start;
	private final BigDecimal stop;
	private final BigDecimal step;
	
	public NumberGenerator(BigDecimal start, BigDecimal stop, BigDecimal step) {
		this.start = start;
		this.step = step;
		this.stop = stop;
	}

	public Iterable<? extends Entry<String, ? extends SequentialAny>> entries() {
		return Utils.wrapIterator(new EntriesIterator());
	}
	
	public boolean isEmpty() {
	    return !(new EntriesIterator().hasNext());
	}
	
	public boolean isSimpleType() {
	    return start.add(step).compareTo(stop) > 0;
	}

}

